
LIBNAME fm 'D:\Dropbox\Dual_Class_Paper\Financial Management Submission\Data Code';

%LET threshold = 0.05;  

DATA t1;
SET fm.merged_data_cleaned;


PROC SORT DATA=t1;
BY unique_id date;

DATA t1;
SET t1;
BY unique_id;

prc_lag1=lag1(prc);
shrout_lag1=lag1(shrout);
IF first.unique_id THEN DO;
						prc_lag1=.;
						shrout_lag1=.;
					 END;
ME_lag1=prc_lag1*shrout_lag1;

IF family_vote>&threshold THEN choice=1;
				          ELSE IF family_vote>0.05 THEN choice=0;
						  						ELSE choice=-1;	

ff48_ind_adj_ret_ew=ret*100-indff48_mean_vw_ret;
ff48_ind_adj_ret_ew_vw=ff48_ind_adj_ret_ew*ME_lag1;


ret=ret*100-rf;
ret_vw=ret*ME_lag1;


PROC SORT DATA=t1;
BY choice date;

PROC MEANS MEAN MEDIAN T N DATA=t1;
BY choice;
VAR ret;

PROC MEANS MEAN MEDIAN T N DATA=t1 NOPRINT;
BY choice date;
VAR ret ret_vw ff48_ind_adj_ret_ew ME_lag1;
OUTPUT OUT=m1 MEAN(ret ff48_ind_adj_ret_ew mkt_rf smb hml mom)=ret ff48_ind_adj_ret_ew mkt_rf smb hml mom
			   SUM(ret_vw ff48_ind_adj_ret_ew_vw ME_lag1)=ret_vw ff48_ind_adj_ret_ew_vw ME_sum;

DATA m1_long;
SET m1;
WHERE choice=1;
ret_vw=ret_vw/ME_sum;
ff48_ind_adj_ret_ew_vw=ff48_ind_adj_ret_ew_vw/ME_sum;
KEEP ret date ret_vw ff48_ind_adj_ret_ew ff48_ind_adj_ret_ew_vw mkt_rf smb hml mom _FREQ_;
RENAME ret=ret_long ret_vw=ret_vw_long ff48_ind_adj_ret_ew=ff48_ind_adj_ret_ew_long ff48_ind_adj_ret_ew_vw=ff48_ind_adj_ret_ew_vw_long _FREQ_=N_long;

DATA m1_short;
SET m1;
WHERE choice=-1;
ret_vw=ret_vw/ME_sum;
ff48_ind_adj_ret_ew_vw=ff48_ind_adj_ret_ew_vw/ME_sum;
KEEP ret date ret_vw ff48_ind_adj_ret_ew ff48_ind_adj_ret_ew_vw _FREQ_;
RENAME ret=ret_short ret_vw=ret_vw_short ff48_ind_adj_ret_ew=ff48_ind_adj_ret_ew_short ff48_ind_adj_ret_ew_vw=ff48_ind_adj_ret_ew_vw_short _FREQ_=N_short;

PROC SORT DATA=m1_long;
BY date;

PROC SORT DATA=m1_short;
BY date;

DATA test;
MERGE m1_long m1_short;
BY date;
diff=ret_long-ret_short;
diff_vw=ret_vw_long-ret_vw_short;
diff_ind=ff48_ind_adj_ret_ew_long-ff48_ind_adj_ret_ew_short;
diff_ind_vw=ff48_ind_adj_ret_ew_vw_long-ff48_ind_adj_ret_ew_vw_short;

PROC MEANS MEAN MEDIAN T N DATE=test;

PROC REG DATA=test;
MODEL diff = mkt_rf smb hml mom / EDF;
OUTPUT OUT=test1 p=alpha_vw_long;

PROC REG DATA=test;
MODEL ret_vw_long = mkt_rf smb hml mom / EDF;
OUTPUT OUT=test1 p=alpha_vw_long;

PROC REG DATA=test1;
MODEL ret_vw_short = mkt_rf smb hml mom / EDF;
OUTPUT OUT=test2 p=alpha_vw_short;

DATA test2;
SET test2;
alpha_diff=alpha_vw_long-alpha_vw_short;

PROC MEANS MEAN MEDIAN T N DATA=test2;
VAR ret_long ret_vw_long diff diff_vw diff_ind diff_ind_vw alpha_vw_long alpha_vw_short alpha_diff;

DATA test2;
SET test2;
excess_ret=ret_long;
weight1=1;
dummy=1;

PROC REG DATA=test2 OUTEST=est_all0 TABLEOUT NOPRINT;
MODEL excess_ret = dummy / EDF;
WEIGHT weight1;

PROC REG DATA=test2 OUTEST=est_all1 TABLEOUT NOPRINT;
MODEL excess_ret = mkt_rf / EDF;
WEIGHT weight1;

PROC REG DATA=test2 OUTEST=est_all2 TABLEOUT NOPRINT;
MODEL excess_ret = mkt_rf smb hml / EDF;
WEIGHT weight1;

PROC REG DATA=test2 OUTEST=est_all3 TABLEOUT NOPRINT;
MODEL excess_ret = mkt_rf smb hml mom / EDF;
WEIGHT weight1;

DATA results;
SET est_all3 est_all2 est_all1  est_all0;
WHERE _TYPE_='PARMS' OR _TYPE_='T' 
KEEP Intercept mkt_rf smb hml mom _TYPE_ _RSQ_;
RENAME Intercept=alpha _TYPE_=VAR _RSQ_=RSQ;

PROC PRINT DATA=results;

RUN;
